﻿//#define NOT_DEFINED_CONSTANT;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;


namespace AFCEPF.BankApplication.BLL
{



/*  Cette classe ne sera compilée que si 
 *  la constante NOT_DEFINED_CONSTANT est définie
 *  (avec #define NOM_CONSTANTE).. 
    */
#if NOT_DEFINED_CONSTANT

    /// <summary>
    /// Strongly-typed AccountBase List that encapsulates
    /// a List(of TAccount)
    /// </summary>
    /// <typeparam name="TAccount">The type of the account.</typeparam>
    public class AccountList<TAccount> : IEnumerable<TAccount>  where TAccount: AccountBase
    {
        private List<TAccount>  _innerList;
        

        /// <summary>
        /// Ctor
        /// </summary>
        public AccountList()
        {
            // Let's instantiate the inner list..
            _innerList  = new List<TAccount>();
            
        }

        /// <summary>
        /// Creates the specified account.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="deposit">The deposit.</param>
        /// <returns>the specified account</returns>
        public TAccount Create(Customer customer, double deposit)
        {
            TAccount result;
            result = (TAccount)AccountFactory.CreateAccount(customer, deposit);


            // Let's wire the newly created Account's events
            // to event handlers in the Bank class.
            result.NegativeBalanceWithdraw += Bank.Instance.OnAccountNegativeBalanceWithdraw;
            result.OverLimitWithdraw += Bank.Instance.OnOverLimitWithdraw;

            _innerList.Add(result);           
            
            return result;
        }



        /// <summary>
        /// Clears this instance.
        /// </summary>
        public void Clear()
        {
            _innerList.Clear();
        }

        #region -- IEnumerable<TAccount> Members --

        /// <summary>
        /// Retourne un énumérateur qui parcourt la collection.
        /// </summary>
        /// <returns>
        ///   <see cref="T:System.Collections.Generic.IEnumerator`1"/> pouvant être utilisé pour parcourir la collection.
        /// </returns>
        IEnumerator<TAccount> IEnumerable<TAccount>.GetEnumerator()
        {
            return _innerList.GetEnumerator();
        }

        #endregion

        #region -- IEnumerable Members --

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return _innerList.GetEnumerator();
        }

        #endregion
    }
#endif
}
